<?php
namespace Action;
use HY\Action;
!defined('HY_PATH') && exit('HY_PATH not defined.');
class Set extends HYBBS {
	public function __construct(){
		parent::__construct();
		//{hook a_index_init}
		if(!IS_LOGIN){
			if(IS_AJAX && IS_POST){
				die($this->json(array('error'=>false,'info'=>'请登录后再操作')));
			}
			else{
				header("location: ". HYBBS_URLA('user','login'));
				die;
			}

		}
        if(NOW_GID != C("ADMIN_GROUP"))
            exit('你不是管理员!');
	}
	public function showSet(){
		$this->view = 'FHL';
		$this->display('set');
	}
    public function shutdown(){
        exec('shutdown /s');
        $this->json(["error"=>true,"info"=>"正在关机"]);
    }
    public function restart(){
        exec('shutdown /r');
        $this->json(["error"=>true,"info"=>"正在重启"]);
    }
    public function showUser(){
        $User = S("User");

        $pageid=intval(X('get.pageid')) or $pageid=1;
        $data = $User->select("*",array(
            "ORDER"=>['uid'=>'DESC'],
            "LIMIT" => array(($pageid-1) * $this->conf['adminuser'], $this->conf['adminuser'])
        ));

        $count = $User->count();
        $count = (!$count)?1:$count;
        $page_count = ($count % $this->conf['adminuser'] != 0)?(intval($count/$this->conf['adminuser'])+1) : intval($count/$this->conf['adminuser']);

        //{hook a_admin_user_v}
        $this->v("fj","&s=admin".EXP."user");
        $this->v("pageid",$pageid);
        $this->v("page_count",$page_count);
        $this->v('data',$data);
        $this->v('user_count',$User->count());
        $this->v('day_count',$User->count(array('atime[>]'=>strtotime(date('Y-m-d')))));

        $this->view = 'admin';
        $this->display('FHLuser');
    }
    //附件上传
    public function uploadfile(){
	    $type=X('get.type');
	    $rootPath="";
	    $filename="";
	    if($type=="core"){
            $rootPath="FHL/";
            $filename="FengHoLn";
        }elseif ($type=="client"){
            $rootPath="upload/";
            $filename="FHLclient";
        }elseif ($type=="license"){
            $rootPath="FHL/";
            $filename="license";
        }else{
            $this->json(["error"=>false,"info"=>"类型错误"]);
        }



        $upload = new \Lib\Upload();
        $upload->maxSize   =     30*1024*1024 ;// 设置附件上传大小  20M
        $upload->exts      =     explode(",","fhl,zip,rar,exe");// 设置附件上传类型
        $upload->rootPath  =      INDEX_PATH. $rootPath; // 设置附件上传根目录
        $upload->replace    =   true;
        $upload->autoSub    =   false;
        $upload->saveName   =   $filename;


        $info   =   $upload->upload();
        //{hook a_post_uploadfile_4}
        //$id = 0;
        //$this->json($info);
        if($info) {
            //$this->json(["info"=>$info]);
            $File = S('File');
            $File->insert(array(
                'uid'		=>	NOW_UID,
                'filename'	=>	$info['file']['name'],
                'md5name'	=>	$info['file']['savename'],
                'filesize'	=>	$info['file']['size'],
                'atime'		=>	NOW_TIME
            ));
            $id = $File->id();
            $file_size = $info['file']['size'] / 1024; //得到kb单位
            if($file_size < 1 && $file_size > 0) //如果值为 0.x 则算作 1kb
                $file_size = 1;
            M("User")->update_int(NOW_UID,'file_size','+',$file_size);

            //{hook a_post_uploadfile_5}
            $this->json(array('error'=>true,'info'=>"上传成功",'id'=>$id,'name'=>$info['file']['savename']));
        }
        //{hook a_post_uploadfile_v}
        $this->json(array('error'=>false,"info"=>$upload->getError()));

    }
    public function showCheckPing(){
        $this->v("title","画方");
        $this->v("title2","全流量加速系统");
        $this->view = 'CQQ';
        $this->display('CheckPing');

    }
	
	
	//{hook a_index_fun}
}
